<template>
  <div class="address">
    <van-address-edit
      :area-list="areaList"
      :address-info="addressInfo"
      show-postal
      show-delete
      show-set-default
      show-search-result
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import { Toast } from "vant";
import { areaList } from "@vant/area-data";
export default {
  data() {
    return {
      areaList,
      addressInfo: {
        name: "猪猪",
        tel: "17613060377",
        province: "河南省",
        city: "郑州市",
        county: "高新区",
        addressDetail: "威科姆科技园",
        postalCode: "450001",
        isDefault: true,
      },
    };
  },
  methods: {
    onSave(content) {
      console.log(content);
      this.addressInfo = content;
      this.$store.commit("address/changereceiver", content.name);
      this.$store.commit(
        "address/changeregions",
        content.province + "/" + content.city + "/" + content.county
      );
      this.$store.commit("address/changeaddress", content.addressDetail);

      localStorage.setItem(
        "address",
        JSON.stringify({
          receiver: content.name,
          regions: content.province + "/" + content.city + "/" + content.county,
          address: content.addressDetail,
        })
      );
      this.$router.push("/cart");
    },
    onDelete() {
      Toast("delete");
    },
    onChangeDetail(val) {
      console.log(val);
    },
  },
};
</script>

<style scoped></style>
